"use strict";
exports.__esModule = true;
/*
 * @Author: your name
 * @Date: 2020-08-28 11:40:09
 * @LastEditTime: 2020-09-01 16:45:46
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /express/src/utils/iwencai/analyzer.ts
 */
var fs_1 = require("fs");
var cheerio_1 = require("cheerio");
var DellAnalyzer = /** @class */ (function () {
    function DellAnalyzer() {
    }
    DellAnalyzer.getInstance = function () {
        if (!DellAnalyzer.instance) {
            DellAnalyzer.instance = new DellAnalyzer();
        }
        return DellAnalyzer.instance;
    };
    DellAnalyzer.prototype.getCourseInfo = function (html) {
        var $ = cheerio_1["default"].load(html);
        var result = $('#resultWrap');
        var table = result.find('.static_table');
        var queryInfoArr = [];
        console.log(table);
        debugger;
        queryInfoItems.map(function (index, element) {
            var wordBox = $(element).find('.word_box');
            var itemIcon = $(element).find('.item_icon');
            var queryLink = wordBox.find('.query_link');
            var queryDesc = wordBox.find('.query_info');
            var title = queryLink.eq(0).text();
            var url = queryLink.attr('href');
            var desc = queryDesc.eq(0).text();
            var type = itemIcon.eq(0).text();
            queryInfoArr.unshift({ title: title, url: url, desc: desc, type: type });
        });
        return {
            time: new Date().getTime(),
            data: queryInfoArr
        };
    };
    DellAnalyzer.prototype.generateJsonContent = function (courseInfo, filePath, resetData) {
        var fileContent = {};
        if (fs_1["default"].existsSync(filePath)) {
            if (!resetData) {
                fileContent = JSON.parse(fs_1["default"].readFileSync(filePath, 'utf-8'));
            }
        }
        fileContent[courseInfo.time] = courseInfo.data;
        return fileContent;
    };
    DellAnalyzer.prototype.analyze = function (html, filePath, resetData) {
        var courseInfo = this.getCourseInfo(html);
        var fileContent = this.generateJsonContent(courseInfo, filePath, resetData);
        return JSON.stringify(fileContent);
    };
    return DellAnalyzer;
}());
exports["default"] = DellAnalyzer;
